package com.lagou.homework03;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class IoTest {
    public static void main(String[] args) {

        BufferedReader br = null;
        PrintStream ps = null;
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            ps = new PrintStream(new FileOutputStream("./abc.txt"));
            //定义一个list集合
            Collection c1 = new ArrayList();
            while (true) {
                //提示用户输入要发送的内容并使用变量记录
                System.out.println("请输入要记录的内容");
                String str = br.readLine();
                //判断用户输入的内容是否为"end"
                if ("end".equals(str)) {
                    System.out.println("输入结束");
                    break;
                } else {
                    //将输入的字符串添加到集合中
                    c1.add(str);
                }
            }
            //将集合转化为数组
            Object[] objects = c1.toArray();
            System.out.println(Arrays.toString(objects));
            //将数组进行排序
            Arrays.sort(objects);
            System.out.println(Arrays.toString(objects));
            //将数组逆序输入到文本中
            for (int i = 0 ; i <= objects.length -1; i++){
                ps.println(objects[objects.length-1-i]);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //关闭
            if (null != ps){
                ps.close();
            }
            //关闭
            if (null != br){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
